package exercise;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Set;

/**
 * @classname:HashMapDemo
 * @description:
 * @author: Mr.Z
 * @date: 2020/12/20 23:55
 * @version: 0.1
 * @since:1.8
 */
public class HashMapDemo {
    public static void main(String[] args) {
        HashMap<String,Integer> map = new HashMap<>();
        map.put("sad",1);
        map.put("ssf",2);
        map.put("grg",3);
        map.put("ced",4);
//        map.forEach(new BiConsumer<String, Integer>() {
//            @Override
//            public void accept(String s, Integer integer) {
//                System.out.println(s+":"+integer);
//            }
//        });

//        Set<Map.Entry<String, Integer>> entries = map.entrySet();
//        for (Map.Entry<String, Integer> entry : entries) {
//            System.out.println(entry.getKey()+":"+entry.getValue());
//        }

        Set<String> keySet = map.keySet();
        Iterator<String> iterator = keySet.iterator();
        while (iterator.hasNext()){
            String key = iterator.next();
            System.out.println(key+":"+map.get(key));
        }


//        Set<Map.Entry<String, Integer>> entries = map.entrySet();
//        Iterator<Map.Entry<String, Integer>> iterator = entries.iterator();
//        while (iterator.hasNext()){
//            Map.Entry<String, Integer> next = iterator.next();
//            System.out.println(next.getKey()+":"+next.getValue());
//        }
        System.out.println("--------");

//        LinkedHashMap<String,Integer> listmap = new LinkedHashMap<>();
//        listmap.put("sad",1);
//        listmap.put("ssf",2);
//        listmap.put("grg",3);
//        listmap.put("ced",4);





//        Set<Map.Entry<String, Integer>> entriesq = map.entrySet();
//        Iterator<Map.Entry<String, Integer>> iteratorq = entriesq.iterator();
//        while (iteratorq.hasNext()){
//            Map.Entry<String, Integer> nextq = iteratorq.next();
//            System.out.println(nextq.getKey()+":"+nextq.getValue());
//        }



    }
}
